package com.deer.im.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.deer.im.message.ByteMessage;
import com.deer.im.service.IMessageService;

@Service
public class MessageService implements IMessageService {

	@Autowired
	private SimpMessagingTemplate messagingTemplate;

	@Override
	public void subscribeByte(Map<String, Object> headers, byte[] payload) {
		// 实时推送到/topic/node主题上，发送字节消息
		messagingTemplate.convertAndSend("/topic/node", new ByteMessage(payload));
	}

	@Override
	public void send(String message){
		JSONObject msgJson = JSONObject.parseObject(message);
        messagingTemplate.convertAndSend("/topic/node",msgJson);
    }
}
